package com.qgz.googleapp.service.imp;

import java.util.List;
import java.util.logging.Logger;

import com.google.inject.Inject;
import com.qgz.googleapp.dao.DaoUser;
import com.qgz.googleapp.entity.User;
import com.qgz.googleapp.service.UserService;

public class UserServiceImp implements UserService {
	
	Logger log =Logger.getLogger(UserServiceImp.class.getName());
	
	@Inject
	private DaoUser daoUser;		
	
	public void AddNewUser(String email, String password) {
		// TODO Auto-generated method stub
		daoUser.AddNewUser(email, password);
	}

	public User delUser(String email) {
		// TODO Auto-generated method stub
		return daoUser.delUser(email);
	}

	public User getUser(String email) {
		// TODO Auto-generated method stub
		return daoUser.getUser(email);
	}

	public User delUser(User user) {
		// TODO Auto-generated method stub
		if(null == user){
			log.warning("delete user is null.");
			return null;
		}
		if("".equals(user.getEmail())){
			log.warning("delete user's email is empty.");
			return null;
		}
		log.info("delete user:"+user.getEmail());
		
		return daoUser.delUser(user.getEmail());
	}

	public User editUser(User user) {
		// TODO Auto-generated method stub
		
		User temp = daoUser.getUser(user.getEmail());
		if (null == temp){
			log.warning("edit user is not exist."+user.getEmail());
			return null;
		}
		temp.setEmail(user.getEmail());
		temp.setPassword(user.getPassword());
		
		daoUser.updateUser(temp);
		
		return temp;
	}

	public boolean isEmailExist(String email) {
		User user = daoUser.getUser(email);
		if (user == null){
			return false;
		}else{
			return true;
		}
		
	}

	public boolean isRegistUser(String email, String password) {

		User user = daoUser.getUser(email);
		if (user == null){
			return false;
		}
		if(email.equals(user.getEmail())&&password.equals(password)){
			return true;
		}else{
			return false;
		}
	}

	public boolean login(String email, String password) {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean logout(User user) {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean regist(String email, String password) {
		// TODO Auto-generated method stub
		return false;
	}

	public List<User> getAllUser() {
		// TODO Auto-generated method stub
		
		return daoUser.listAllUser();
	}

}
